package net.huashitong.Project.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Project.entity.MessageList;
import net.huashitong.Project.filter.MessageListFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MessageListDao extends StringDao<MessageList> {

    public List<MessageList> queryByFilterNoPage(MessageListFilter filter){
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getUserId())) {
            query.append(" and obj.userId =:userId").setParam("userId",filter.getUserId());
        }
        if(ObjectUtils.isNotBlank(filter.getIsRead())){
            query.append(" and obj.isRead =:isRead").setParam("isRead",filter.getIsRead());
        }
        if(ObjectUtils.isNotBlank(filter.getTaskId())){
            query.append(" and obj.taskId =:taskId").setParam("taskId",filter.getTaskId());
        }
        return query.listResult();
    }

    public List<MessageList> queryByFilter(MessageListFilter filter){
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getUserId())) {
            query.append(" and obj.userId =:userId").setParam("userId",filter.getUserId());
        }
        if(ObjectUtils.isNotBlank(filter.getIsRead())){
            query.append(" and obj.isRead =:isRead").setParam("isRead",filter.getIsRead());
        }
        if(ObjectUtils.isNotBlank(filter.getTaskId())){
            query.append(" and obj.taskId =:taskId").setParam("taskId",filter.getTaskId());
        }
        return query.listResult(filter);
    }
}
